﻿/// <reference path="_namespace.js" />
/// <reference path="Container.js" />
/// <reference path="IMenuItemContainer.js" />
/// <reference path="MenuItem.js" />

/*****************************************************************************
Ajax library class definition. Kevin Robinson 2006.
Class: ajax.components.MenuBar
/*****************************************************************************/


ajax.lang.addNamespace("ajax.components");

//-----------------------------------------------------------------------------
ajax.components.MenuBar = function(doc, parentObject, parentNode)  // public: Constructor
{    
    ajax.components.MenuBar.superConstructor.call(this, doc, parentNode, "", 100, 24); 
    this.parentObject       = parentObject;          
    this.units.size.width   = "%";  
    
    this.layerStyle = 
    {
        position        : "relative",
        overflow        : "hidden",
        backgroundColor : "#EEEEEE",
        fontFamily      : "Arial",
        fontSize        : "12px"                
    }
    this.menuItems          = null;    

}

//-----------------------------------------------------------------------------
ajax.lang.extend("ajax.components.MenuBar", "ajax.components.Container"); // Inherit
// Now say that we support the MenuItemContainer interface
ajax.lang.supports("ajax.components.MenuBar", "ajax.components.IMenuItemContainer"); // Interface
if ($getDesignMode())
    ajax.components.MenuBar.prototype = ajax.components.Container.prototype;

//-----------------------------------------------------------------------------
// Overrides
ajax.components.MenuBar.prototype.create = function()
{    
    ajax.components.MenuBar.superClass.create.call(this);
        
    // Create Menu Items object
    this.menuItems   = ajax.lang.safeNew("ajax.components.MenuItemContainer", this.doc, this, this.layer);
    this.layer.menuBar  = this;       
    
}



//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Support the MenuItemContainer Interface like we say we do
ajax.components.MenuBar.prototype.add_itemSelected    = function(handler) { return this.getEvent(this.getWindow(), "onItemSelected").addListener(handler); };
ajax.components.MenuBar.prototype.remove_itemSelected = function(handler) { return this.getEvent(this.getWindow(), "onItemSelected").removeListener(handler); };

ajax.components.MenuBar.prototype.addMenuItem = function(menuItem, width)
{    
    // The MenuItem must be set to display horizontally
    menuItem.setDisplayHorizontal(true, width);
    // Add it to the menu Items
    return this.menuItems.addMenuItem(menuItem);
}

ajax.components.MenuBar.prototype.removeMenuItem = function(menuItem)
{
    return this.menuItems.removeMenuItem(menuItem);
}

ajax.components.MenuBar.prototype.getMenuItem = function(sKey)
{///<returns type="ajax.components.MenuItem"/>
    return this.menuItems.getMenuItem(sKey);
}



//-----------------------------------------------------------------------------
ajax.components.MenuBar.prototype.toString = function()
{
    return "ajax.components.MenuBar";
}

//-----------------------------------------------------------------------------
ajax.components.MenuBar.prototype.toClassName = function()
{
    return ajax.lang.getClassName("ajax.components.MenuBar");
}


//-----------------------------------------------------------------------------
ajax.components.MenuBar.cast = function(obj)
{///<returns type="ajax.components.MenuBar"/>
    return obj;
}